/*
 * =============================================================================
 * Copyright (c) 2008 Exaid. All rights reserved.
 * =============================================================================
 */

/*
 * ErrorBox.java
 *
 * Created on Feb 13, 2009, 9:51:28 AM
 */
package sfsui;

import java.util.logging.Level;
import java.util.logging.LogRecord;

/**
 *
 * @author eirikb
 */
public class SFSUIErrorBox extends javax.swing.JDialog {

    /** Creates new form ErrorBox */
    public SFSUIErrorBox(java.awt.Frame parent) {
        super(parent);
        initComponents();
    }

    public void log(LogRecord record) {
        String error = "\nMessage: " + record.getMessage();
        error += "\nLogger: " + record.getLoggerName();
        error += "\nSource class: " + record.getSourceClassName();
        error += "\nMethod: " + record.getSourceMethodName();
        error += "\nTime: " + record.getMillis();
        error += "\nThrown: " + record.getThrown().toString();
        error += "\nStacktrace:";
        for (StackTraceElement element : record.getThrown().getStackTrace()) {
            error += "\n" + element.toString();
        }
        error += '\n';

        if (record.getLevel().equals(Level.SEVERE)) {
            severeTextBox.append(error);
        } else if (record.getLevel().equals(Level.WARNING)) {
            warningTextBox.append(error);
        } else if (record.getLevel().equals(Level.INFO)) {
            infoTextBox.append(error);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        errorTabbedPane = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        severeTextBox = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        warningTextBox = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        infoTextBox = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        errorTabbedPane.setName("errorTabbedPane"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        severeTextBox.setColumns(20);
        severeTextBox.setRows(5);
        severeTextBox.setName("severeTextBox"); // NOI18N
        jScrollPane1.setViewportView(severeTextBox);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sfsui.SFSUIApp.class).getContext().getResourceMap(SFSUIErrorBox.class);
        errorTabbedPane.addTab(resourceMap.getString("jScrollPane1.TabConstraints.tabTitle"), jScrollPane1); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        warningTextBox.setColumns(20);
        warningTextBox.setRows(5);
        warningTextBox.setName("warningTextBox"); // NOI18N
        jScrollPane2.setViewportView(warningTextBox);

        errorTabbedPane.addTab(resourceMap.getString("jScrollPane2.TabConstraints.tabTitle"), jScrollPane2); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        infoTextBox.setColumns(20);
        infoTextBox.setRows(5);
        infoTextBox.setName("infoTextBox"); // NOI18N
        jScrollPane3.setViewportView(infoTextBox);

        errorTabbedPane.addTab(resourceMap.getString("jScrollPane3.TabConstraints.tabTitle"), jScrollPane3); // NOI18N

        getContentPane().add(errorTabbedPane, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane errorTabbedPane;
    private javax.swing.JTextArea infoTextBox;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextArea severeTextBox;
    private javax.swing.JTextArea warningTextBox;
    // End of variables declaration//GEN-END:variables
}
